packages


tSNE

test several options and choose optimal perplexity in: data, perplexities out: plots

library(Rtsne)
library(ggplot2)
find_optimal_p_tSNE <- function(perplexities, data) {
  for (p in perplexities) {
    tsne_out <- Rtsne(as.matrix(train), perplexity = p)
    plot(tsne_out$Y)
  }
}

in: ion data optimal perplexity out: (x,y) coordinates

run_tSNE <- function(data, optimal_p) {
  all_tsne_out <- Rtsne(as.matrix(data), perplexity = optimal_p)
  tsne_coords <- as.data.frame(all_tsne_out$Y)
  return(tsne_coords)
}

PCA

in: ion data out: (x,y) coordinates

run_PCA <- function(data) {
  res <- prcomp(data)$x
  return(res[,c(1,2)])
}


dmontemayor/Rcricvol documentation built on Sept. 9, 2021, 9:12 a.m.